package per.yhh.xxxtsj.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class Message<T> implements Serializable {
    private Meta meta;
    private T data;

    public static Message ok(Object result) {
        return new Message<>(new Meta(200), result);
    }

    public static Message failed() {
        return new Message<>(new Meta(400), null);
    }
    public static Message failed(String msg) {
        return new Message<>(new Meta(400), msg);
    }
    public static Message Unauthorized(String msg) {
        return new Message<>(new Meta(401), msg);
    }
    public static Message InsufficientPermissions() {
        return new Message<>(new Meta(403), "权限不足");
    }
    public int getCode() {
        return meta.getStatus();
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    static class Meta {
        Integer status;
    }
}
